package com.chzc.fm.duotin.adapter.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.channel.Rank;

import java.util.List;

/**
 * Created by Administrator on 2016/6/29.
 */
public class RankCommentAdapter extends RecyclerView.Adapter<RankCommentAdapter.RankTodayViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private List<Rank> rankList;

    public RankCommentAdapter(Context context, List<Rank> rankList) {
        this.context = context;
        this.rankList = rankList;

        inflater = LayoutInflater.from(context);
    }

    @Override
    public RankTodayViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = inflater.inflate(R.layout.adapter_rank_listen,null);
        return new RankTodayViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RankTodayViewHolder holder, int position) {

        Rank rank = rankList.get(position);
        int num = position+1;
        String string = num +"  "+ rank.getTitle();
        SpannableString spannableString = new SpannableString(string);
        ForegroundColorSpan span = new ForegroundColorSpan(context.getResources().getColor(R.color.public_gray));

        if (position == 0) {
            span= new ForegroundColorSpan(context.getResources().getColor(R.color.firstcolor));
            spannableString.setSpan(span, 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        }else if (position == 1 || position == 2)
        {
            span= new ForegroundColorSpan(context.getResources().getColor(R.color.colorPublic));
            spannableString.setSpan(span, 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        }else
        if (position < 8 && position > 2 )
        {
            span = new ForegroundColorSpan(context.getResources().getColor(R.color.public_gray));
            spannableString.setSpan(span, 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        spannableString.setSpan(span, 0, 2, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.tvconten.setText(spannableString);

        holder.imageView.setImageResource(R.drawable.ic_rank_comment);
        holder.tvplaynum.setText(rank.getComment_num());
    }

    @Override
    public int getItemCount() {
        return rankList == null ? 0 : rankList.size();
    }

    public class RankTodayViewHolder extends RecyclerView.ViewHolder {

        TextView tvplaynum,tvconten;
        ImageView imageView;

        public RankTodayViewHolder(View itemView) {
            super(itemView);

            tvconten = (TextView) itemView.findViewById(R.id.adapter_rank_today_coneten_tv);
            tvplaynum = (TextView) itemView.findViewById(R.id.adapter_rank_today_playnum_tv);
            imageView = (ImageView) itemView.findViewById(R.id.adapter_rank_today_iv);
        }
    }
}
